<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$idSetDati = reqVarInt('sd');
$sqlSel = "SELECT d.* "
		." FROM rgl_def_dato d "
		." WHERE d.cod_dato = '".reqVarAS('cd')."' AND d.id_set_dati = ".$idSetDati;
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("var. cd. '$idSetDati/".reqVar('cd')."' mancante o errato");
}
$_REQUEST = array_merge($acRec,$_REQUEST);
$aCamForm = array();
require("_inc/const.campiDato.php");

if (reqVar('azione') == 'elimina') {
	$msgPag = eliminaDato($aCamForm);
} 

$sCmdL = "";
$sCmdL .= "<a class='cmd1' href='../../ratg/cbil/calcDato.php?sd=$idSetDati&cd=".reqVar('cd')."&xsn=".XSN."' >test</a>";

$sCmdR = "";
$sCmdR .= "<a class='cmd1' href='datoMod.php?sd=$idSetDati&cd=".reqVar('cd')."&xsn=".XSN."' >modifica</a>";
$sCmdR .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class='cmd1' href='javascript:confEli();' >elimina</a>";
$sCmdR .=  cmdTorna('torna'); 

testaHtml('Gestione modelli',$msgPag,'modl');
?>
<script type="text/javascript">
<!--
function confEli() {
	if (confirm("Confermi ?")) {
		document.location.href = "datoMod.php?azione=elimina&cd=<?=reqVar('cd')?>&xsn=<?=XSN?>";
	}
}
//-->
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <? echo $sCmdL; ?>
      </td>
      <td class="cmd1" align="right">
         <? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<?
echo getHtmlForm('frm1','',array('enctype'=>true));
echo getHtmlHidden('azione','salva');
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('cd');
echo getHtmlHidden('sd');
?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Definizione Dato</td>
   </tr>
<?
// elimina campo script se vuoto
if (reqvarTrim('script')=='') {
	foreach($aCamForm as $rr => $aX) {
		foreach($aX as $cc => $aY) {
			if ($aY[0]=='script') {
				unset($aCamForm[$rr][$cc]);
				break 2;
			}
		}
	}
}
echo getHtmlCampiForm($aCamForm,'vis');
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <? echo $sCmdL; ?>
      </td>
      <td class="cmd1" align="right">
         <? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

function eliminaDato($aCamForm) {
	global $objDB;
	$msg = '';
	$sSql = "DELETE FROM rgl_def_dato "
		."WHERE id_set_dati = ".reqVar('sd')." AND cod_dato = '".reqVarAS('cd')."'";
	$objDB->exec($sSql);
	$newId = $objDB->lastInsertId('insRec');
	
	header("Location: ".urlTorna("Dato '".reqVar('cod_dato')."' eliminato"));
	exit();
}
